<?php

require( "../Application.php"); 

$tweetVO = new TweetVO();

$tweetUrl = "http://search.twitter.com/search.json?rpp=100&geocode=40.63664,-79.71668999999997,5mi";
 $curl = curl_init();
    curl_setopt ($curl, CURLOPT_URL, $tweetUrl);
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
    $twitterResponse = curl_exec ($curl);
    curl_close ($curl);
    $rawJSON = json_decode($twitterResponse, true);
    $result = array();
    for ($i = 0; $i < count($rawJSON["results"]);$i++){
      $rawItem = $rawJSON["results"][$i];
      $tweetVO->from_user = $rawItem["from_user"];
      $tweetVO->geo = $rawItem["geo"];
      $tweetVO->location = $rawItem["location"];
      $tweetVO->profile_image_url = $rawItem["profile_image_url"];
      $tweetVO->text = $rawItem["text"];
      
      if(!is_null($tweetVO->geo)){
        $tweetVO->lat = $tweetVO->geo["coordinates"][0];
        $tweetVO->lng = $tweetVO->geo["coordinates"][1];
      }
      var_dump($tweetVO);
      echo "<p>";
      array_push($result, $tweetVO);
    }
?>